<?php

namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Branch extends Model
{
    protected $table='branchs';
    protected $table_name='branchs';

    protected $fillable = [
        'id', 'branch_name', 'created_at', 'updated_at'
    ];

    //通过ID获取团队
    public function getBranchByID($id)
    {
        $res = DB::table($this->table_name)->where('id',$id)->first();
        if(!$res){
            return false;
        }
        $res = json_decode(json_encode($res),true);
        if(!is_array($res) || count($res)<1){
            return false;
        }
        return $res;
    }

    //获取团队列表
    public function getBranchList()
    {
        $res = DB::table($this->table_name)->where("mall_id", request()->mallData["id"])->get();
        if(!$res){
            return false;
        }
        $res = json_decode(json_encode($res),true);
        if(!is_array($res) || count($res)<1){
            return false;
        }
        return $res;
    }
}
